{extend name="layout:base" /}

{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">我的钱包</div>
        <div class="layui-card-body layui-text">
            <table class="layui-table" style="text-align: center">
                <thead>
                <tr>
                    <th style="text-align: center">账户余额</th>
                    <th style="text-align: center">冻结金额</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>{$myData.money}</td>
                    <td>{$myData.M_money}</td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>

    {if condition="$myData.money > 0 "}
    <div class="layui-card layui-hide">
        <div class="layui-card-header">提现</div>
        <div class="layui-card-body">
            <form class="layui-form">
                <div class="layui-row layui-col-space10 layui-form-item">
                    <label class="layui-form-label">账户余额</label>
                    <div class="layui-input-inline">
                        <input type="number" name="money" id="money"  value="{$myData.money}"  autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-row layui-col-space10 layui-form-item">
                    <label class="layui-form-label">金额</label>
                    <div class="layui-input-inline">
                        <input type="number" name="num" id="num" value="" lay-verify="num" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="" >
                            <button class="layui-btn" lay-submit="" lay-filter="btn_cash">保存</button>
                            <a class="layui-btn layui-btn-primary" href="javascript:parent.location.reload();">返回</a>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
    {/if}


    <div class="layui-card layui-hide">
        <div class="layui-card-header">申请记录</div>
        <div class="layui-card-body">
            <table class="layui-table"  lay-data="{page:true, id:'test'}" lay-filter="test">
                <thead>
                <tr>
                    <th lay-data="{field:'id'}"></th>
                    <th lay-data="{field:'name'}">标题</th>
                    <th lay-data="{field:'intime'}">时间</th>
                    <th lay-data="{field:'state'}">状态</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    {volist name="applyList" id="vo" }
                    <td>{$i}</td>
                    <td>{$vo.name}</td>
                    <td>{$vo.intime}</td>
                    <td>
                        {if condition="$vo.state==0"}审核中{/if}
                        {if condition="$vo.state==1"}审核通过，等待转账{/if}
                        {if condition="$vo.state==2"}已转账{/if}
                    </td>
                    {/volist}
                </tr>
                </tbody>
            </table>
        </div>
    </div>

    <div class="layui-card">
        <div class="layui-card-header">资金变更</div>
        <div class="layui-card-body">
            <table id="tbList" class="layui-table" lay-filter="tbList" ></table>
        </div>
    </div>
</div>

{/block}

{block name="script"}
<script>
    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'util','form','laydate'], function () {
        var $ = layui.$,form = layui.form,layer = layui.layer,table = layui.table,laydate = layui.laydate;

        table.render({
            elem: '#tbList',
            url: "{:url('getMy')}",
            toolbar: '#toolbarDemo',
            totalRow: true,
            cellMinWidth: 80,
            cols: [[
                {type: 'checkbox', fixed: 'left'},
                {field: 'id', fixed: 'left', title: 'ID',width:66, totalRowText: '合计',sort: false},
                {field: 'typeid',fixed: 'left',title: '平台', templet:'#typeid'},
                {field: 'Name',fixed: 'left',title: '关键词'},
                {field: 'keypm',  title: '排名'},
                {field: 'money',  title: '消费', totalRow: true},
                {field: 'intime',  title: '扣费时间',width:120},
                {fixed: 'right', title: '操作',width:200, toolbar: '#op'}
            ]],
            page: true,
            limit:15
        });
        form.verify({
            num: function(value){
                if(value < 1){
                    return '请输入大于0的数字';
                }
            }
        });

        form.on('submit(btn_cash)', function (data) {
            console.log(data.field);
            if(data.field.num > Number(data.field.money) ){
                layer.msg('提现金额不能超出余额哦', {icon: 3, time: 3000});
                return false;
            }
            $.post("{:url('my')}", data.field, function (result) {
                if (result['code'] == 0) {
                    layer.msg(result['msg'], {icon: 1, time: 1000}, function () {
                       location.reload();
                    });
                } else {
                    layer.msg(result['msg'], {icon: 3, time: 3000});
                }
            });
            return false;
        });
    });

</script>
{/block}